import type { Context } from 'koa';
import { UserService } from '@/services/user';
import { ResponseErrors } from '@/enums/responseErrors';

type QueryType = {
  userId?: string;
}

// 获取用户信息
export const userProfileController = async (ctx: Context) => {
  const input = ctx.request.body || {} as QueryType;
  const { userId = ctx.userId } = input;
  const user = await UserService.findUserByIdAndOmitPassword(userId);

  if (!user) {
    ctx.sendError(ResponseErrors.userNotExist);
    return;
  }

  return ctx.sendSuccess(user);
}
